﻿Imports System.Windows.Controls
Imports System.Windows

Public Class WindowsFromsChartZone
    Inherits DashboardZone


    Dim _Visual As New System.Windows.Forms.Integration.WindowsFormsHost
    Dim _DataProperty As DashboardZoneProperty
    Dim _ChartProperty As DashboardZoneProperty

    Sub New()

        Dim chart = New System.Windows.Forms.DataVisualization.Charting.Chart()
        chart.ChartAreas.Add("standard")
        chart.Series.Add("standard").ChartArea = "standard"
        chart.Series("standard").Points.AddY(1.5)
        chart.Series("standard").Points.AddY(0.5)
        chart.Series("standard").Points.AddY(2.5)
        Me._Visual.Child = chart
        Me._DataProperty = New DashboardZoneProperty(Me, "Data", GetType(IEnumerable))
        Me._DataProperty.EnableDimensionOnBinding = True
        Me.Properties.Add(_DataProperty)

        Me._ChartProperty = New DashboardZoneProperty(Me, Me._Visual, "Child", "Defaut", "Graphe")
        Me.Properties.Add(_ChartProperty)
       

    End Sub

    'Public Property Grid As DataGrid
    '    Get
    '        Return _Visual
    '    End Get
    '    Set(value As DataGrid)
    '        _Visual = value
    '    End Set
    'End Property

    Public Overrides ReadOnly Property Visual As UIElement
        Get
            Return _Visual
        End Get
    End Property


    Protected Friend Overrides Sub OnValueChanged([Property] As DashboardZoneProperty)
        'If [Property] Is _DataProperty Then
        '    Dim v = TryCast(_DataProperty.Value, DataView)
        '    AddHandler v.ListChanged, AddressOf DataViewListChanged
        '    If v IsNot Nothing Then
        '        If _DataProperty.DataBinding IsNot Nothing Then
        '            Me._Visual.ItemsSource = _DataProperty.Value
        '            'Me._Visual.Series(0).DataMapping = "Label=Member;Value=" & "_" & _DataProperty.DataBinding.Aggregate & "_" & _DataProperty.DataBinding.DataMember.Name
        '        End If
        '    End If
        'End If

        'If [Property].PropertyType.IsSubclassOf(GetType(DataGridColumn)) Then

        'End If
    End Sub

    Private Sub DataViewListChanged(sender As Object, e As ComponentModel.ListChangedEventArgs)
        '  MsgBox(e.ListChangedType.ToString() & ":" & e.NewIndex & ":" & e.OldIndex & ":" & If(e.PropertyDescriptor IsNot Nothing, e.PropertyDescriptor.Name, "nothing"))
    End Sub

    Protected Friend Overrides Sub OnDeserializeVisual(ByVal visual As System.Windows.UIElement)
        MyBase.OnDeserializeVisual(visual)
        Me._Visual = visual
    End Sub

    Private Sub VisualAutoGeneratedColumns(sender As Object, e As EventArgs)
        'Me.Properties.Clear()
        'Me.Properties.Add(_DataProperty)
        'Me.Properties.Add(Me._ChartProperty)
        'For Each c In Me._Visual.Columns
        '    Dim prop = New DashboardZoneProperty(Me, c.Header, c.GetType())
        '    prop.Value = c
        '    prop.Group = "Columns"
        '    Me.Properties.Add(prop)

        'Next
    End Sub



End Class
